<!--************************************************************************************************-->
<!-- < mainPage.php >                                                                               -->
<!-- Copyright (c) 2012-2013 San Yat-sun University School of Software                              -->
<!-- Founder & Modifier: Xiaoxin Mo                                                                 -->
<!-- Stu : 10389159                                                                                 -->                                                                         
<!--                                                                                                -->
<!-- Version : 2.1                                                                                  -->
<!-- LastUpdate : 2013-01-01 14:30 BY Xiaoxin Mo                                                      -->
<!-- add exist function -->
<!--************************************************************************************************-->


<?php 
	include_once("../db/User.php");
	
	class UserManager{
		static $instance;
		private $user;
		
		public function __construct(){
		}
		
		public static function getInstance(){
			if (self::$instance == null)
				self::$instance = new self();
			return self::$instance;
		}
		
		public function register($array){
			$user = new User($array);
			$user->insert();
			return true;
		}
		
		public function delete($array){
			$user = new User($array);
			$user->delete();
		}
		
		public function update($array){
			$user = new User($array);
			$user->update();
		}
		
		public function getValueById($id){
			$user = new User(null);
			return $user->findValueById($id);
		}
		
		public function getNUsers($N){
			$user = new User(null);
			return $user->findNUsers($N);
		}
		
		public function getNUsernames($N){
			$user = new User(null);
			return $user->findNUsernames($N);
		}
		
		// ================added by xiaoxin
		public function getUsernameById($id){
			$user_value = mysql_fetch_array($this->getValueById($id));
			return $user_value['Username'];
		}
		
		public function getValueByUsername($username){
			$user = new User(null);
			return $user->findValueByUsername($username);
		}
		
		public function getIDByUsername($username){
			$result = $this->getValueByUsername($username);
			return $result['ID'];
		}
		
		public function getPasswordByUsername($username){
			$result = $this->getValueByUsername($username);
			return $result['Password'];
		}
		
		public function getBooklistByUsername($username){
			$user = new User(null);
			return $user->findBooklistByUsername($username);
		}
		
		public function getGrouplistByUsername($username)
		{
			$user = new User(null);
			return $user->getGroupnamelistByUsername($username);
		}
		
		// ======================added by Xiaoxin at 2013-01-01 14:30=========
		public function exist($name){
			if ($this->getValueByUsername($name) == null)
				return false;
			return true;
		}
	}
?>